import { ImageResponse } from "next/og"; import type { Fact } from "src/replicache"; import type { Attribute } from "src/replicache/attributes"; import { Database } from "../../supabase/database.types"; import { createServerClient } from "@supabase/ssr"; import { parseHSBToRGB } from "src/utils/parseHSB"; // Route segment config export const revalidate = 0; export const preferredRegion = ["sfo1"]; export const dynamic = "force-dynamic"; export const fetchCache = "default-no-store"; // Image metadata export const size = { width: 32, height: 32, }; export const contentType = "image/png"; // Image generation let supabase = createServerClient( process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, process.env.SUPABASE_SERVICE_ROLE_KEY as string, { cookies: {} }, ); export default async function Icon(props: { params: { leaflet_id: string } }) { let res = await supabase .from("permission_tokens") .select("*, permission_token_rights(*)") .eq("id", props.params.leaflet_id) .single(); let rootEntity = res.data?.root_entity; let outlineColor, fillColor; if (rootEntity && res.data) { let { data } = await supabase.rpc("get_facts", { root: rootEntity, }); let initialFacts = (data as unknown as Fact[]) || []; let themePageBG = initialFacts.find( (f) => f.attribute === "theme/card-background", ) as Fact<"theme/card-background"> | undefined; let themePrimary = initialFacts.find( (f) => f.attribute === "theme/primary", ) as Fact<"theme/primary"> | undefined; outlineColor = parseHSBToRGB(`hsba(${themePageBG?.data.value})`); fillColor = parseHSBToRGB(`hsba(${themePrimary?.data.value})`); } return new ImageResponse( ( // ImageResponse JSX element
{/* outline */} {/* fill */}
), // ImageResponse options { // For convenience, we can re-use the exported icons size metadata // config to also set the ImageResponse's width and height. ...size, headers: { "Cache-Control": "no-cache", }, }, ); }